<?php
namespace app\demo\model;

use think\Model;
use traits\model\SoftDelete;
use app\mogosdk\model\Mogo;
class Tags extends Mogo
{
    use SoftDelete;
    protected $table = 'dp_xdk_tags';
    protected $autoWriteTimestamp = true;

    protected function Plan(){
        return $this->belongsToMany('Plan','xdk_plan_tags');
    }
    //添加标签
    public function addTags(){

        $data = request()->only(['name']);

        // 验证
        $validate = new \app\demo\validate\Tags();
        $result =  $validate->check($data);

        if(!$result){
            return  json(['error'=>$validate->getError()],422);
        }
        $tags = self::create($data);

        return json($tags);
    }
}
